package com.fairytask.ui
{
	import com.fairytask.engine.components.BaseItem;
	import com.fairytask.engine.components.Scroll.ScrollPanel;
	import com.fairytask.engine.components.ToolTips;
	import com.fairytask.engine.components.button.Button;
	import com.fairytask.engine.components.clip.Clip;
	import com.fairytask.engine.components.group.ViewGroup;
	import com.fairytask.engine.components.text.Label;
	import com.fairytask.engine.components.text.Text;
	import com.fairytask.engine.data.BaseData;
	import com.fairytask.engine.data.Record;
	import com.fairytask.engine.data.RecordObject;
	import com.fairytask.engine.data.View;
	import com.fairytask.engine.define.Filter;
	import com.fairytask.engine.define.MenuType;
	import com.fairytask.engine.define.RecordDefine;
	import com.fairytask.engine.define.ResConfig;
	import com.fairytask.engine.define.ViewDefine;
	import com.fairytask.engine.managers.ResManager;
	import com.fairytask.engine.resource.StaticIni;
	import com.fairytask.engine.utils.IO;
	import com.jzonl.logic.SceneLogic;
	import com.jzonl.managers.TipsManage;
	import com.jzonl.managers.ViewManage;
	import com.jzonl.net.event.CustomToClientEvent;
	import com.jzonl.net.messages.CustomToServerFlag;
	import com.jzonl.net.mgr.NetMgr;
	import com.jzonl.stage.charactor.Player;
	import com.jzonl.tools.GoodSet;
	import com.jzonl.tools.TaskTools;
	import com.fairytask.ui.base.FrameUI;
	
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	import flash.geom.Point;
	import flash.text.StyleSheet;
	import flash.text.TextField;
	import flash.text.TextFieldType;
	
	/**
	 * Npc弹出框
	 * @author chensl
	 * 
	 */	
	public class NpcTalkUI extends FrameUI
	{
		private static var _self:NpcTalkUI;
		
		public var closeBtn		:Button;
		public var backClip		:MovieClip;
		public var nameLab			:Label;		//NPC名称
		public var descriptionText	:Text;		//NPC描述
		public var linksText		:Text;		//对话框选择
		private var _halfContainer	:Sprite;	//半身像容器
		private var _clip			:Clip;		//半身像图片
		private var _shadow		:MovieClip;	//半身像预加载阴影
		private var _scrollPane	:ScrollPanel;
		private var _container		:Sprite;
		private var _sentStr      :String;
		public var line			:MovieClip;   //下滑线
		
		public var goodLab			:Label;	   //物品
		public var expLbl			:Label	   //经验
		public var awardGoodVg		:ViewGroup;//奖励物品组
		public var expInput		:Label	   //经验 值
		public var silverLbl		:Label	   //银子
		public var silverInput		:Label	   //银子 值
		public var giftPaperLbl	:Label;	   //仙玉
		public var giftPaperInput	:Label;	   //仙玉 值
		public var bindSilverLbl	:Label;	   //灵气
		public var bindSilverInput	:Label;	   //灵气 值 
		public var btn				:Button;	//发送消息的按钮	
		
		public var stateLab		:TextField;//接取任务/领取奖励
		private var taskStateClip	:Clip;	   //任务状态图标
		//数据
		//==============================================================
		private var _npcObj		:Object;
		private var _asyncID		:int;
		private var _npcId			:String;
		private var _functionID	:int;
		
		private var taskRecord			:BaseData=new BaseData();
		private var _data				:Array; //任务数据
		private var taskID				:int;	//任务ID
		private var taskStatus			:int;	//任务状态
		private var viewType			:int;	//窗口类型
		
		public const  TASK_NOT_ACCEPT	:int = 4;//显示  接取任务
		public const  TASK_COMPLETE	:int = 5;//显示  已完成
		private var _task				:String;//任务
		private var _complete			:String;//完成
		private var _close				:String;//关闭
		private var _nextStep			:String;//下一步
		private var _trade				:String;//交易
		private var _accpet			:String;// 接取
		/**
		 *得到单例模式的對象 
		 * @return 
		 * 
		 */		
		public static function getInstance():NpcTalkUI
		{
			if (_self == null)
			{
				_self=new NpcTalkUI;
			}
			return _self;
		}
		public function NpcTalkUI(popupUI:Boolean = true)
		{
			super(popupUI);
			initEvent();
		}
		
		/**
		 *重新写显示 
		 * 
		 */		
		override public function initGUI():void
		{	
			_task = StaticIni.getSwfLangStr("1000000560");			//任务
			_complete = StaticIni.getSwfLangStr("1000000562");		//完成
			_close = StaticIni.getSwfLangStr("Task_Close");		//关闭
			_nextStep = StaticIni.getSwfLangStr("1000000561");		//下一步
			_trade	=	StaticIni.getSwfLangStr("1000000579");		//交易
			_accpet = StaticIni.getSwfLangStr("1000000291");		//接取
			
			_clip = new Clip(true,onLoaded);
			_halfContainer = new Sprite();
			_halfContainer.x = 0;
			_halfContainer.y = -55;
			windowBG.addChild(_halfContainer);
			_shadow =	ResManager.newResClass("SilhouetteNPC") as MovieClip;			
			
			windowBG.removeClose();//隐藏关闭按钮
			//NPC名称
			nameLab = new Label();
			nameLab.color = "24EBF2";
			nameLab.labelFilter = Filter.COMMON_TEXT_FILTER;
			nameLab.x = 15;
			nameLab.y = 202;
			windowBG.addChild(nameLab);
			//NPC描述
			descriptionText=new Text(410,60,"vScrol_1","vScrol_7",true,false,13);
			descriptionText.x=76;
			descriptionText.y=15;	
			descriptionText.setFilter();
			windowBG.addChild(descriptionText);
			
			var txtStyle	:StyleSheet	=	new StyleSheet();
			txtStyle.setStyle("a:link"		,{color:"#"+StaticIni.getIniVar("Css_a_NpcTalk","link"),textDecoration:"underline"});
			txtStyle.setStyle("a:visited"	,{color:"#"+StaticIni.getIniVar("Css_a_NpcTalk","visited")});
			txtStyle.setStyle("a:hover"	,{color:"#"+StaticIni.getIniVar("Css_a_NpcTalk","hover"),textDecoration:"none"});
			//交互连接
			linksText=new Text(400,70,"vScrol_1","vScrol_7");
			linksText.x	=	61;
			linksText.y	=	90;
			linksText.styleSheet	=	txtStyle;
			linksText.setFilter();
			
			windowBG.addChild(linksText);
			//半身像头顶的任务状态的标志
			taskStateClip = new Clip();
			taskStateClip.x = 76;
			taskStateClip.y = 99;
			windowBG.addChild(taskStateClip);
			
			stateLab = new TextField();
			stateLab.height = 25;
			stateLab.type = TextFieldType.DYNAMIC;
			stateLab.selectable = false;
			stateLab.x = 93;
			stateLab.y = 97;
			stateLab.styleSheet = txtStyle;
			stateLab.filters = [Filter.COMMON_TEXT_FILTER];
			stateLab.htmlText = "<a href='event:0'>" + StaticIni.getSwfLangStr("1000000279") + "</a>";
			windowBG.addChild(stateLab);
			
			
			posJustify(0);
		}
		
		/**
		 * 选择菜单选项后领取任务或任务完成领取奖励UI位置调整 
		 * @param type 0.npc选择菜单状态  1.npc接取菜单状态
		 * 
		 */		
		private function posJustify(type:int):void
		{
			if(type == 0)
			{
				line.visible = false;
				goodLab.visible  	= false;
				awardGoodVg.visible = false;
				expLbl.visible 		= false;
				expInput.visible 	= false;
				silverLbl.visible 	= false;
				silverInput.visible = false;
				giftPaperLbl.visible= false;
				giftPaperInput.visible 	= false;
				bindSilverLbl.visible	= false;
				bindSilverInput.visible = false;
				stateLab.visible = false;
				taskStateClip.visible = false;
				btn.label	=	StaticIni.getSwfLangStr("1000000562");		//完成
			}
			else
			{
				line.visible = true;
				goodLab.visible  	= true;
				awardGoodVg.visible = true;
				expLbl.visible 		= true;
				expInput.visible 	= true;
				silverLbl.visible 	= true;
				silverInput.visible = true;
				giftPaperLbl.visible= true;
				giftPaperInput.visible 	= true;
				bindSilverLbl.visible	= true;
				bindSilverInput.visible = true;
				stateLab.visible = true;
				taskStateClip.visible = true;
				btn.label	=	StaticIni.getSwfLangStr("1000000560");   // 任务
			}
		}
		
		/**
		 *初始化事件 
		 * 
		 */		
		private function initEvent():void
		{
			linksText.addLinkClickHandel(onLinkDown);
			closeBtn.addEventListener(MouseEvent.CLICK,onClose);
			//收到后台消息，UI显示
			//model.addEventListener(CustomToClientEvent.SERVER_CUSTOMMSG_OPEN_TASK_ACCEPT_WINDOW,onTask);	
			//任务功能按钮点击
			stateLab.addEventListener(MouseEvent.CLICK,onSubmitTask);
			awardGoodVg.addItemsEvent(MouseEvent.ROLL_OVER,onShowTip);
			awardGoodVg.addItemsEvent(MouseEvent.ROLL_OUT,onHideTip);
			btn.addEventListener(MouseEvent.CLICK,sendMessage);
		}
		
		/**
		 *返送消息给服务器 
		 * @param evt
		 * 
		 */		
		private function sendMessage(evt:MouseEvent):void
		{
			var label:String	=	btn.label;
			switch(label)
			{
				case _task:
				case _trade:
					//NetMgr.sendCustomMsg(CustomToServerFlag.CLIENT_SELECTMENU,_npcObj,_functionID);
					break;
				case _complete:
					//NetMgr.sendCustomMsg(CustomToServerFlag.CLIENT_CUSTOMMSG_TASK_CONFIRM_SUBMIT,taskID);
					break;
				case _close:
					break;
				case _nextStep:
					var num:Array = _sentStr.split(",");
					//NetMgr.sendCustomMsg(CustomToServerFlag.CLIENT_SELECTMENU,_npcObj,[_functionID,int(num[1]),int(num[2])]);
					////NetMgr.sendCustomMsg(CustomToServerFlag.CLIENT_SELECTMENU,_npcObj,strArr);
					break;
				case _accpet:
					//NetMgr.sendCustomMsg(CustomToServerFlag.CLIENT_CUSTOMMSG_TASK_CONFIRM_ACCEPT,taskID);
					break;
					
					
			}
			this.hide();
		}
		
		/**z
		 *显示tips 
		 * @param evt
		 * @param index
		 * 
		 */		
		private function onShowTip(evt:MouseEvent,index:int):void
		{
			if(awardGoodVg.getItemByIndex(index).data.CheckProperties("configID"))
			{
				var configID:int = awardGoodVg.getItemByIndex(index).data.GetProperties("configID");
				TipsManage.ShowAllItemsTips(int(StaticIni.getIniVar(String(configID),"ItemType")),configID);
			}
		}
		
		private function onHideTip(evt:MouseEvent,index:int):void
		{
			ToolTips.hide();
		}
		
		
		/**
		 * 得到消息后自己现实npc对话框
		 * @param evt
		 * 
		 */		
		public function onTask(evt:CustomToClientEvent):void
		{
			show();
			posJustify(1);
			this.data	=	evt.pList;
		}
		
		public function set data(value:Array):void
		{
			cleanVGroup();
			_data = value;
			linksText.htmlStr	=	"";
			descriptionText.htmlStr	=	"";
			
			_npcObj		=	_data[0];//说话对象
			
			var str:String = npcName(_npcObj);
			var modelId	:String;
			//半身像判定显示
			if(model.scene.CheckProperties(_npcObj.toString()))
			{
				_npcId = model.scene.GetPropertiesEx(_npcObj.toString()).GetPropertiesEx("ConfigID");
				modelId	=	model.scene.GetPropertiesEx(_npcObj.toString()).GetPropertiesEx("Model");
				HalfNpc(modelId);
			}
			//天书NPC半身像
			var tmpTsView	:View	=	model.scene.GetView(ViewDefine.VIEWPORT_TS);
			if(tmpTsView.CheckProperties(_npcObj.toString()))
			{
				_npcId = tmpTsView.GetPropertiesEx(_npcObj.toString()).GetPropertiesEx("ConfigID");
				if(int(StaticIni.getIniVar(_npcId,"hasPhoto"))==1)
				{
					modelId	=	tmpTsView.GetPropertiesEx(_npcObj.toString()).GetPropertiesEx("Model");
					HalfNpc(modelId);
				}
			}
			
			//任务id
			taskID=_data[1];
			//按钮状态:4,接任务;5，完成任务
			taskStatus=_data[2];
			var killCount		:int = 0;
			
			//任务描述===========================================================
			descriptionText.htmlStr	=	"";
			switch(taskStatus)
			{
				case TASK_NOT_ACCEPT:
					stateLab.htmlText="<a href='event:0'>" + StaticIni.getSwfLangStr("1000000279") + "</a>";//显示  接取任务
					btn.label	=	_accpet;
					descriptionText.htmlStr	=	StaticIni.getSwfLangStr("TaskCaption_"+taskID);
					break;
				case TASK_COMPLETE:
					stateLab.htmlText="<a href='event:0'>" + StaticIni.getSwfLangStr("1000000280") + "</a>";//显示  领取奖励	
					btn.label	=	StaticIni.getSwfLangStr("1000000562");
					descriptionText.htmlStr	= "<textformat>" + StaticIni.getSwfLangStr("TaskDlgOnCompleted_"+taskID) + "</textformat>";
					break;
				default:
					stateLab.htmlText= "<a href='event:0'>" + StaticIni.getSwfLangStr("1000000279") + "</a>";//显示  接取任务
					btn.label	=	_accpet;
					descriptionText.htmlStr	= "<a>" + StaticIni.getSwfLangStr("TaskCaption_"+taskID) + "</a>";
			}
			
			//任务奖励===========================================================
			//经验
			var isFloat	:Boolean	=	Boolean(int(StaticIni.getIniVar(taskID,"RepeatProMul")));
			var plyLvel	:int		=	Player.instance.data.GetProperties("Level");
			var acceptRec:Record = model.scene.GetRecordEx(RecordDefine.TASK_ACCEPTED);
			acceptRec.getDataForEach(function(key:String,val:*):void
			{
				if(val is RecordObject)
				{
					if(val.GetProperties("0") == taskID)
					{
						plyLvel = val.GetProperties("8");
					}
				}
			});
			expInput.htmlStrByBorder="";
			var awardExp	:String	=	StaticIni.getIniVar(taskID,"AwardExp");
			var levelVal	:String	=	StaticIni.getIniVar(taskID,"Level");
			var initID	:int	=	int(StaticIni.getIniVar(taskID,"InitTask"));
			
			if(awardExp!=null)
			{
				if(isFloat)
				{
					//人物最终经验 = 标准经验 * ( 0.9 + 环数 * 0.1 ）*（（100 –任务推荐等级）* 0.01  + 接取任务时人物等级*0.01）
					awardExp	=	String(TaskTools.getAwardReal(int(awardExp),int(levelVal),plyLvel,initID,int(StaticIni.getIniVar(taskID,"Type"))));
					//awardExp	=	String(int(int(awardExp)*(0.9+TaskTools.getInstance().getRound(initID)*0.1)*((100-int(levelVal))*0.01+plyLvel*0.01)));
				}
				expInput.htmlStrByBorder 	=	awardExp;
			}
			//银子
			silverInput.htmlStrByBorder	=	"";
			var awardMoney	:String	=	StaticIni.getIniVar(taskID,"AwardMoney");
			var awardGold	:String	=	StaticIni.getIniVar(taskID,"AwardGold");
			if(null	!=	awardMoney)
			{
				if(isFloat)
				{
					//awardMoney = String(int(int(awardMoney)*(0.9+TaskTools.getRepeatTaskRound()*0.1)*((100-int(levelVal))*0.01+plyLvel*0.01)));
					awardMoney	=	String(TaskTools.getAwardReal(int(awardMoney),int(levelVal),plyLvel,initID,0));
				}
					silverInput.htmlStrByBorder	=	awardMoney;

				
			}
			if(awardGold!=null)
			{
				giftPaperInput.htmlStrByBorder	=	awardGold;
			}
			else
			{
				giftPaperInput.htmlStrByBorder	=	"";
			}
			
			//门贡(系数*当前环数)
			if(int(StaticIni.getIniVar(taskID,"Type")) == 3)//为师门任务
			{
				//根任务为接取状态,值不显示
				if(initID == 0)
				{
					giftPaperInput.htmlStrByBorder = "";
				}else
				{
					giftPaperInput.htmlStrByBorder = String(int(StaticIni.getIniVar("PartyDevoteTask","param"))*TaskTools.getInstance().getRound(initID));
				}
			}
			
			//灵气
			var awardSpirit : String = StaticIni.getIniVar(taskID,"AwardSpirit");//灵
			if(awardSpirit!=null && awardSpirit!="")
			{
				if(isFloat)
				{
					//bindSilverInput.htmlStrByBorder = String(int(int(awardSpirit)*(0.9+TaskTools.getInstance().getRound(initID)*0.1)*((100-int(levelVal))*0.01+plyLvel*0.01)));
					bindSilverInput.htmlStrByBorder = String(TaskTools.getAwardReal(int(awardSpirit),int(levelVal),plyLvel,initID,0));
				}else
				{
					bindSilverInput.htmlStrByBorder = awardSpirit;
				}
			}
			
			//奖励
			var propList:Array = [];//总物品数组
			var fitArr	:Array = [];//符合条件数组
			var itemStr:String = StaticIni.getIniVar(taskID,"AwardItem");
			if((itemStr!="")&&(itemStr!=null))//有任务奖励
			{
				propList =	itemStr.split(";");
				var dataArr	 : Array = [];
				var configID : int;//物品id
				var num : int;		//物品数量
				var adaptProfType : int;//物品限制门派类型(0:无限制 1:蜀山 2:昆仑 3:蓬莱 4:天机 5:明王)
				var needSex : int;		//物品限制性别类型(0:无 1:男 2:女)
				var i:int = 0;
				for (;i<propList.length;i++)
				{
					dataArr		=	propList[i].split(",");
					configID	=	dataArr[0];//物品ID 
					num			=	dataArr[1];//物品数量
					adaptProfType = int(StaticIni.getIniVar(configID,"AdaptProfType"));
					needSex		=	int(StaticIni.getIniVar(configID,"NeedSex"));
					if( (needSex == 0||needSex == Player.instance.data.GetProperties("Sex")) && (adaptProfType == 0||adaptProfType == Player.instance.data.GetProperties("Nation")))
					{
						fitArr.push(propList[i]);
					}
				}
				
				//放置奖励物品
				for(i=0;i<fitArr.length;i++)
				{
					dataArr		=	fitArr[i].split(",");
					configID	=	dataArr[0];//物品ID 
					num			=	dataArr[1];//物品数量
					
					var sprite:Sprite=new Sprite()
					var tmpItem:Clip=new Clip(true,onItemLoad,"jzLogo");
					var numlab:Label=new Label();
					var bindIcon:Sprite=new Sprite();
					tmpItem.source=ResConfig.iconPath + StaticIni.getIniVar(configID, "Icon") + ResConfig.iconImg; 
					tmpItem.x	=	tmpItem.y	=	2;
					
					//物品框颜色设置
					var frameData:Array = GoodSet.getFrameData(configID);
					if(num==0)
					{
						num =1;
					}
					GoodSet.setNumPos(numlab,num);
					sprite.addChild(tmpItem);
					sprite.addChild(frameData[0]);
					sprite.addChild(numlab);
					sprite.x = sprite.y	=	0;
					awardGoodVg.getItemByIndex(i).addItem(sprite);
					awardGoodVg.getItemByIndex(i).data.HandleProperties("configID",configID);
				}
			}
			
			//按钮状态
			switch(taskStatus)
			{
				case TASK_NOT_ACCEPT:
					stateLab.htmlText= "<a href='event:0'>" + StaticIni.getSwfLangStr("1000000279") + "</a>";//显示  接取任务
					taskStateClip.source = ResConfig.pngTaskPath+"Task_Accept.png";
					break;
				case TASK_COMPLETE:
					stateLab.htmlText= "<a href='event:0'>" + StaticIni.getSwfLangStr("1000000280") + "</a>";//显示  领取奖励	
					taskStateClip.source = ResConfig.pngTaskPath+"Task_Completed.png";
					break;
			}
		}
		
		private function onItemLoad(val:Clip):void
		{
			
		}
		
		/**
		 * 清空VGroup 
		 */		
		private function cleanVGroup():void
		{
			descriptionText.htmlStr = "";
			expInput.htmlStr 		= "";
			silverInput.htmlStr 	= "";
			giftPaperInput.htmlStr 	= "";
			bindSilverInput.htmlStr = "";
			taskStateClip.clear();
			
			awardGoodVg.getItemForEach(function (tmpItem:BaseItem):void
			{
				tmpItem.clear();
				tmpItem.data.clearProperties();
			});
		}
		
		private function onSubmitTask(evt:MouseEvent):void
		{
			switch(taskStatus)
			{
				case TASK_NOT_ACCEPT:
					//NetMgr.sendCustomMsg(CustomToServerFlag.CLIENT_CUSTOMMSG_TASK_CONFIRM_ACCEPT,taskID);
					break;//接受任务
				case TASK_COMPLETE:
					//NetMgr.sendCustomMsg(CustomToServerFlag.CLIENT_CUSTOMMSG_TASK_CONFIRM_SUBMIT,taskID);
					break;//完成任务
			}
			hide();
		}
		
		private function npcName(obj:Object):String
		{
			if(!model.scene.CheckProperties(obj.toString()))
			{
				var tmpView	:View	=	model.scene.GetView(ViewDefine.VIEWPORT_TS);
				//检查是不是天书里的npc
				if(tmpView.CheckProperties(obj.toString()))
				{
					return StaticIni.getSwfLangStr(tmpView.GetProperties(obj.toString()).GetPropertiesEx("NameID"));
				}
				else
				{
					return "";
				}
			}
			var obj1:String = StaticIni.getSwfLangStr(model.scene.GetPropertiesEx(obj.toString()).GetPropertiesEx("NameID"));
			return StaticIni.getSwfLangStr(model.scene.GetPropertiesEx(obj.toString()).GetPropertiesEx("NameID"));
		}
		
		
		
		/**
		 *根据数据服务器的消息进行显示npc对话框 
		 * @param pList
		 * 
		 */		
		public function onGetNPCInfo(pList:Array):void
		{
			IO.traceLog("NPC对话显示了~");
			//先清除显示
			posJustify(0);
			show();
			
			linksText.htmlStr	=	"";
			descriptionText.htmlStr	=	"";
			
			_npcObj	=	pList.shift();//说话对象
			_asyncID	=	pList.shift();//异步事件标识
			
			var modelId	:String;
			//半身像判定显示
			if(model.scene.CheckProperties(_npcObj.toString()))
			{
				_npcId = model.scene.GetPropertiesEx(_npcObj.toString()).GetPropertiesEx("ConfigID");
				modelId	=	model.scene.GetPropertiesEx(_npcObj.toString()).GetPropertiesEx("Model");
				HalfNpc(modelId);
				nameLab.htmlStrByBorder = "<font size='18'>" + StaticIni.getSwfLangStrVar("npccolor",[npcName(_npcObj)]) + "</font>";
			}
			//天书NPC半身像
			var tmpTsView	:View	=	model.scene.GetView(ViewDefine.VIEWPORT_TS);
			if(tmpTsView.CheckProperties(_npcObj.toString()))
			{
				_npcId = tmpTsView.GetPropertiesEx(_npcObj.toString()).GetPropertiesEx("ConfigID");
				if(int(StaticIni.getIniVar(_npcId,"hasPhoto"))==1)
				{
					modelId	=	tmpTsView.GetPropertiesEx(_npcObj.toString()).GetPropertiesEx("Model");
					HalfNpc(modelId);
					nameLab.htmlStrByBorder = "<font size='18'>" + StaticIni.getSwfLangStrVar("npccolor",[npcName(_npcObj)]) + "</font>";
				}
			}
			
			var itemCount	:int	=	pList.shift();//菜单条数
			var num:int=3;
			
			
			//菜单消息
			//参数 object	npc			//说话对象
			//参数 int		asyncID		//异步事件标识
			//参数 int		nCount		//菜单条数 一共有几行数据
			//参数 int		nType;		//类型，0纯文字，1过场，2选项，3左右，4是否关闭
			//参数 int		funcType;	//功能号类型
			//参数 int		nfuncid;	//功能号
			//参数 string	text;		//文字
			//参数 int		argsCount	//这条菜单的参数条数
			//参数 ...
			//(x=284, y=0),0,3,0,0,0,NPCDes_11050312,0,2,1,65200,TaskName_21000002,2,Task_Completed,1,2,0,60000,Task_Close,0 
			var firstID   :int  = -1;
			outerLoop: for(var i:int=0;i<itemCount;i++)
			{
				var _type   :int		=   pList.shift();//类型
				var _funcType:int   =    pList.shift();//功能号类型
				var _funcID	:int	=	pList.shift();//功能号
				var _testStr	:String	=	pList.shift();//文字
				var _menuNum:int    =   pList.shift();//这条菜单的参数条数
				//开始答题NPC:Funcid_SelectIndex_AnswerQestion = 50208,
//				if(GuidePopUI.getInstance().txtId=="4002006974")
//				{
//					if(_funcID==50208)
//					{
//						this.addPopUI(GuidePopUI.getInstance());
//					}
//					else
//					{
//						GuidePopUI.getInstance().hide();
//					}
//				}
				_functionID = _funcID;
				if(i == 1)
				{
					firstID = _funcID;
				}
					
				switch (_type)
				{
					case MenuType.MENU_TEXT:
						descriptionText.htmlStr	=	StaticIni.getSwfLangStr(_testStr);
						btn.label	=	StaticIni.getSwfLangStr("Task_Close");
						break;
					case MenuType.MENU_GUIDE:
						descriptionText.htmlStr	=	StaticIni.getSwfLangStrVar("npccolor",[npcName(_npcObj)])+"<br>"+StaticIni.getSwfLangStr(_testStr);
						break;
					case MenuType.MENU_SELECT:
						menuSelect(pList,_funcType,_funcID,_testStr,_menuNum,i==1);
						break;
					case MenuType.MENU_SIDE:
						break;
					//					case MenuType.MENU_CLOSE:		//关闭
					//						linksText.htmlStr	+="<textformat leftmargin='14'>"+ "<a href='event:"+_funcID+"'>"+StaticIni.getSwfLangStr(_testStr)+"</a><br></textformat>";
					//						break;
				}
				//临时屏蔽生活技能学习
				//				if(_testStr=="NPCDes_11050380")
				//				{
				//					menuSelect(pList,0,60000,"Task_Close",0);
				//					break outerLoop;
				//				}
			}
			if(firstID != -1)
				_functionID = firstID;
		}
		
		private function onClose(evt:MouseEvent):void
		{
			this.hide();
		}
		
		public function get npcId():String
		{
			return _npcId;
		}
		
		/**
		 * 添加NPC半身像 
		 * 
		 */		
		private function HalfNpc(npcId:String):void
		{
			_halfContainer.addChild(_shadow);
			_shadow.x = -58;
			_shadow.y = 84;
			nameLab.x = (_shadow.width - nameLab.width)/2 - 88;
			_clip.source     	= ResConfig.pngNpcPath + npcId + ".png";
		}
		
		/**
		 * 半身像图片加载完成处理 
		 * 
		 */		
		private function onLoaded(val:Object):void
		{
			if(_halfContainer.contains(_shadow))
			{
				_halfContainer.removeChild(_shadow);
			}
			_halfContainer.addChild(_clip);
			_clip.x = -108;
			_clip.y = 14;
			nameLab.x = (_clip.width - nameLab.width)/2 - 108;
		}
		
		/**
		 * 有选择的菜单 
		 * @param pList
		 * @param _funcType
		 * @param _funcID
		 * @param _testStr
		 * @param _menuNum
		 * @param Str
		 * 
		 */
		private function menuSelect(pList:Array,_funcType:int,_funcID:int,_testStr:String,_menuNum:int,isfirst:Boolean):void
		{
			var firstLabel:String = btn.label;
			btn.label	=	_nextStep;
			var Str:*;
			var j:int	=	0;
			var num:int=3;
			switch (_funcType)
			{
				case MenuType.MENU_FUNC_TYPE_DEFAULT:
					//关闭选项屏蔽掉(后台不应该发，临时屏蔽)
					if(_funcID == 60000)
					{
						return;
					}
					//默认功能类型，不管参数
					linksText.htmlStr	+="<textformat leftmargin='14'>"+"<a href='event:"+_funcID+"'>"+StaticIni.getSwfLangStr(_testStr)+"</a><br></textformat>";
					break;
				case MenuType.MENU_FUNC_TYPE_TASK_STATUS:
					//任务状态，参数为(任务状态)
					if(_menuNum>0)
					{
						//必然是3个参数
						//任务状态 任务类型 精力值
						var tmpStatus	:String	=	pList.shift();
						var tmptype		:int	=	pList.shift();
						var tmpSp		:int	=	0;
						if(_menuNum>2)
						{
							tmpSp	=	pList.shift();
						}
						_menuNum	-=	3;
						
						linksText.htmlStr	+= "<img src='"+ResConfig.pngResPath+"task/"+tmpStatus+".png' hspace='0' vspace='0'/>";
						linksText.htmlStr	+= "<a href='event:"+_funcID+"'>"+StaticIni.getSwfLangStr(_testStr);
						linksText.htmlStr	+="("+StaticIni.getSwfLangStr(tmpStatus)+")";
						//根据任务的状态来显示按钮的名字
						if(tmpStatus=="Task_Completed")
						{
							btn.label	=	StaticIni.getSwfLangStr("1000000560");
						}
						if(tmpStatus =="Task_Uncomplete")
						{
							btn.label	=	StaticIni.getSwfLangStr("Task_Close");
						}
						if(tmpStatus =="Task_Accept")
						{
							btn.label = _task;
						}
			
						//精力消耗
						if(tmpSp>0)
						{
							linksText.htmlStr	+= StaticIni.getSwfLangStrVar("1000000282",[tmpSp]);
						}
						
						if(_menuNum>0)
						{
							pList.shift();
						}
						
						/*for(j=0;j<_menuNum;j++)
						{
						Str      = pList.shift();
						if(isNaN(Str))
						{
						//NPC 对话小图标
						linksText.htmlStr	+= "<img src='"+ResConfig.pngResPath+"task/"+Str+".png' hspace='0' vspace='0'/>";
						linksText.htmlStr	+= "<a href='event:"+_funcID+"'>"+StaticIni.getSwfLangStr(_testStr);
						linksText.htmlStr	+="("+StaticIni.getSwfLangStr(Str)+")";
						//精力消耗
						//linksText.htmlStr	+= StaticIni.getSwfLangStrVar("4002006148",[pList.shift()]);
						}
						num++;
						}*/
					}
					else
					{
						linksText.htmlStr	+= "    <a href='event:"+_funcID+"'>"+StaticIni.getSwfLangStr(_testStr);
						btn.label	=	StaticIni.getSwfLangStr("1000000561");
					}
					linksText.htmlStr  +="</a><br>";
					break;
				case MenuType.MENU_FUNC_TYPE_TASK_ECHO:	
					//任务应答，参数为任务编号
					if(_menuNum>0)
					{
						Str="";
						for(j=0;j<_menuNum;j++)
						{
							Str     += ","+pList.shift();
							num+=1;
						}
						linksText.htmlStr	+= "<textformat leftmargin='14'>"+"<a href='event:"+_funcID+""+Str+"'>"+StaticIni.getSwfLangStr(_testStr)+"</a><br></textformat>";	 
					}
					else
					{
						linksText.htmlStr	+=	"<textformat leftmargin='14'>"+ "<a href='event:"+_funcID+"'>"+StaticIni.getSwfLangStr(_testStr)+"</a><br></textformat>";
						btn.label	=	StaticIni.getSwfLangStr("1000000562");
					}
					
					break;
				case MenuType.MENU_FUNC_TYPE_TRADE:
					//交易，参数为交易编号
					if(_menuNum>0)
					{
						Str="";
						for(j=0;j<_menuNum;j++)
						{
							Str     += ","+pList.shift();
							num+=1;
							
						}
						linksText.htmlStr	+=	"<textformat leftmargin='14'>"+"<a href='event:"+_funcID+""+Str+"'>"+StaticIni.getSwfLangStr(_testStr)+"</a><br></textformat>";	 
					}
					else
					{
						linksText.htmlStr	+= "<textformat leftmargin='14'>"+"<a href='event:"+_funcID+"'>"+StaticIni.getSwfLangStr(_testStr)+"</a><br></textformat>";
						btn.label	=	_trade;
					}
					break;
				case MenuType.MENU_FUNC_TYPE_FUNC_ECHO:
					//特殊功能，参数全部返回
					if(_menuNum>0)
					{
						Str="";
						for(j=0;j<_menuNum;j++)
						{
							Str     += ","+pList.shift();
							num+=1;
						}
						linksText.htmlStr	+= "<textformat leftmargin='14'>"+"<a href='event:"+_funcID+""+Str+"'>"+StaticIni.getSwfLangStr(_testStr)+"</a><br></textformat>";	 
					}
					else
					{
						linksText.htmlStr	+= "<textformat leftmargin='14'>"+"<a href='event:"+_funcID+"'>"+StaticIni.getSwfLangStr(_testStr)+"</a><br></textformat>";
					}
					_sentStr = Str;
					break;
			}
			if(!isfirst)
				btn.label = firstLabel;
		}
		
		private function onLinkDown(val:String):void
		{
			if(val.indexOf(",")!=-1)
			{
				var strArr:Array=val.split(",");
				for(var i:int=0;i<strArr.length;i++)
				{
					strArr[i]	=	int(strArr[i]);
				}
				//NetMgr.sendCustomMsg(CustomToServerFlag.CLIENT_SELECTMENU,_npcObj,strArr);
			}
			else
			{
				//NetMgr.sendCustomMsg(CustomToServerFlag.CLIENT_SELECTMENU,_npcObj,int(val));
			}
			this.hide();
		}
		
		/**
		 * 界面打开前 
		 */
		override protected function BeforeShow():void
		{
			if(ArenaUI.isArena())
				ArenaUI.getInstance().changeHide();
			npcPoint	=	new Point(int(StaticIni.getIniVar(npcId,"SiteX")),int(StaticIni.getIniVar(npcId,"SiteY")));
			SceneLogic.instance.npcUIArr.push([this,npcPoint]);
			while(_halfContainer.numChildren>0)
			{
				_halfContainer.removeChildAt(0);
			}
		}
		
		override public function show(space:String=MIDDLELAYER, onshow:Function=null):void
		{
			super.show(space,onshow);
			ViewManage.maskEnable	=	true;
		}		
		override public function hide(e:*=null):void
		{
			super.hide(e);
			ViewManage.maskEnable	=	false;
			_clip.clear();
			while(_halfContainer.numChildren>0)
			{
				_halfContainer.removeChildAt(0);
			}
		}
		
	}
}